using Firestarter.DB.Schema.BO;
using Firestarter.DB.Schema.Test.BO.TestUtils;
using FireStarterModeller.Test;
using NUnit.Framework;
namespace Firestarter.DB.Schema.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for DBPrimaryKeyColumn objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for DBPrimaryKeyColumn.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestDBPrimaryKeyColumn
    {
        [TestFixtureSetUp]
        public void SetupTestFixture()
        {
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            base.SetupFixture();
        }

        [Test]
        public void Test_FixBug()
        {
            //---------------Set up test pack-------------------
            DBPrimaryKeyColumn dbPrimaryKeyCol = TestUtilsDBPrimaryKeyColumn.CreateUnsavedValidDBPrimaryKeyColumn();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            dbPrimaryKeyCol.Column = null;

            //---------------Test Result -----------------------
            Assert.IsNull(dbPrimaryKeyCol.Column);;
        }

        [Test]  
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            DBPrimaryKeyColumn dbPrimaryKeyCol = TestUtilsDBPrimaryKeyColumn.CreateUnsavedValidDBPrimaryKeyColumn();
            //---------------Assert Precondition----------------
            
            //---------------Execute Test ----------------------
            string actualToString = dbPrimaryKeyCol.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dbPrimaryKeyCol.PrimaryKeyDB + " - " + dbPrimaryKeyCol.ColumnName, actualToString);
        }
        [Test]  
        public void Test_ToString_NullColumn()
        {
            //---------------Set up test pack-------------------
            DBPrimaryKeyColumn dbPrimaryKeyCol = TestUtilsDBPrimaryKeyColumn.CreateUnsavedValidDBPrimaryKeyColumn();
            dbPrimaryKeyCol.Column = null;
            //---------------Assert Precondition----------------
            
            //---------------Execute Test ----------------------
            string actualToString = dbPrimaryKeyCol.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dbPrimaryKeyCol.PrimaryKeyDB.Table + " - Primary () - ", actualToString);
        }
        [Test]  
        public void Test_ToString_NullPrimaryKey()
        {
            //---------------Set up test pack-------------------
            DBPrimaryKeyColumn dbPrimaryKeyCol = TestUtilsDBPrimaryKeyColumn.CreateUnsavedValidDBPrimaryKeyColumn();
            dbPrimaryKeyCol.PrimaryKeyDB = null;
            //---------------Assert Precondition----------------
            
            //---------------Execute Test ----------------------
            string actualToString = dbPrimaryKeyCol.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(" - " + dbPrimaryKeyCol.ColumnName, actualToString);
        }  
        [Test]  
        public void Test_ToString_NullPrimaryKeyAndNullColumn()
        {
            //---------------Set up test pack-------------------
            DBPrimaryKeyColumn dbPrimaryKeyCol = TestUtilsDBPrimaryKeyColumn.CreateUnsavedValidDBPrimaryKeyColumn();
            dbPrimaryKeyCol.PrimaryKeyDB = null;
            dbPrimaryKeyCol.Column = null;
            //---------------Assert Precondition----------------
            
            //---------------Execute Test ----------------------
            string actualToString = dbPrimaryKeyCol.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(" - ", actualToString);
        }

        [Test]
        public void Test_ColumnName_WhenColumnNull_ShouldRetEmptyString()
        {
            //---------------Set up test pack-------------------
            DBPrimaryKeyColumn pkColumn = new DBPrimaryKeyColumn();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNull(pkColumn.Column);
            //---------------Execute Test ----------------------
            string columnName = pkColumn.ColumnName;
            //---------------Test Result -----------------------
            Assert.IsEmpty(columnName);
        }

        [Test]
        public void Test_ColumnName_WhenColumnNotNull_ShouldRetDBColumnName()
        {
            //---------------Set up test pack-------------------
            DBPrimaryKeyColumn pkColumn = new DBPrimaryKeyColumn();
            string expectedColumnName = GetRandomString();
            pkColumn.Column = new DBColumn(expectedColumnName);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNotNull(pkColumn.Column);
            Assert.IsNotNullOrEmpty(pkColumn.Column.ColumnName);
            //---------------Execute Test ----------------------
            string columnName = pkColumn.ColumnName;
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedColumnName, columnName);
        }

        private static string GetRandomString()
        {
            return TestUtilsShared.GetRandomString();
        }
    }
}